package HUMAN.skiplistviewer;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JPanel;
import javax.swing.JTable;

import HUMAN.controller.SkipListViewerController;
import HUMAN.dto.CriteriaDTO4SkipListViewer;
import HUMAN.view.V_SkipListViewer;
import TOOLS.errCodeManagement;
import TOOLS.messageTool;
import TOOLS.AKtable.m_table;

public class SkipListViewer {
	messageTool mt; 
	V_SkipListViewer p;
	SkipListViewerController ctrller;
	public SkipListViewer() throws Exception {
		mt=SkipListViewerBean.getMessageTool();
		ctrller=SkipListViewerBean.getCtrller();
	}
	
	public void init(JPanel jf,String iNumber) {
		p=SkipListViewerBean.newView();
		p.myRepaint(jf, iNumber);

		p.fields[0].addKeyListener(new KeyAdapter() {
			public void keyPressed(KeyEvent e) {
				if (e.getKeyChar() == KeyEvent.VK_ENTER){
					search();
				}
			}
		});
		p.fields[1].addKeyListener(new KeyAdapter() {
			public void keyPressed(KeyEvent e) {
				if (e.getKeyChar() == KeyEvent.VK_ENTER){
					search();
				}
			}
		});
		p.fields[2].addKeyListener(new KeyAdapter() {
			public void keyPressed(KeyEvent e) {
				if (e.getKeyChar() == KeyEvent.VK_ENTER){
					search();
				}
			}
		});
		p.fields[3].addKeyListener(new KeyAdapter() {
			public void keyPressed(KeyEvent e) {
				if (e.getKeyChar() == KeyEvent.VK_ENTER){
					search();
				}
			}
		});
		p.buttonSearch.addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {//
				search();
			}
		});
		
		
		
		p.show();
	}


	protected void search() {
		try {
			CriteriaDTO4SkipListViewer criteria=new CriteriaDTO4SkipListViewer(p.fields[0].getText(),
					p.fields[1].getText(),p.fields[2].getText(),
					p.fields[3].getText());
			search(criteria);
		} catch (Exception e1) {
			String str=errCodeManagement.getErrText(e1.getMessage());
			mt.show(str);
		}
		
	}

	protected void search(CriteriaDTO4SkipListViewer criteria) throws Exception {
		m_table itable=ctrller.getSkipList(criteria);
		JTable iiT=itable.toJTable();
		p.setTable(iiT,false);
	}
	
	
}
